﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
using AutoMapper;
using YuYuKiCms.Bl.Attribute;
using YuYuKiCms.Bl.Interface;
using YuYuKiCms.Model;

namespace YuYuKiCms.Internet.Controllers
{
    [Authorize]
    [DynamicLayout]
    public class ThemeController : Controller
    {
        private readonly IThemeBL _themeBL;

        public ThemeController(IThemeBL themeBL)
        {
            _themeBL = themeBL;
        }

        /// <summary>
        ///     List all available themes
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var lstTheme = _themeBL.GetAvailableThemes();
            return View(lstTheme);
        }
        
        [HttpPost]
        public JsonResult SetTheme(Int32 id)
        {
            _themeBL.SetTheme(id, Request.MapPath(ConfigurationManager.AppSettings["ThemeIndex"]));
            _themeBL.SetTheme(id, Request.MapPath(ConfigurationManager.AppSettings["ThemeIndex"]));
            return Json(true, JsonRequestBehavior.AllowGet);
        }

        public MvcHtmlString GetCurrentLayout()
        {
            return new MvcHtmlString(_themeBL.GeThemePath());
        }
    }
}